﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace Streambolics.PtBurn
{
    public class PtBurnJob
    {
        private string _Name;
        private PtBurnJobServer _Client;
        private PtBurnJobStatus _Status = PtBurnJobStatus.NotInQueue;
        private bool _FoundInQueue = false;

        internal PtBurnJob (PtBurnJobServer aClient, string aName)
        {
            Contract.Requires (aClient != null);
            Contract.Requires (!String.IsNullOrEmpty (aName));

            _Name = aName;
            _Client = aClient;
            _Client.Add (this);
        }

        public string Name
        {
            get
            {
                return _Name;
            }
        }
        public string StatusText
        {
            get
            {
                return PtBurnTools.StatusToString (Status);
            }
        }

        public PtBurnJobStatus Status
        {
            get
            {
                return _Status;
            }
            set
            {
                _Status = value;
                _FoundInQueue = true;
            }
        }

        internal void BeginUpdateStatus ()
        {
            _FoundInQueue = false;
        }

        internal void EndUpdateStatus ()
        {
            if (!_FoundInQueue)
            {
                Status = PtBurnJobStatus.NotInQueue;
            }
        }
    }
}
